﻿<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
    <script src="~/js/frame.js"></script>
</head>
<body>
    <div class="container-fluid">
        <form id="form">
            <div class="formrow">
                <div class="col-xs-12">
                    <div class="formtitle required">父级部门</div>
                    <div class="formcontent">
                        <cloud-tree id="ParentOUGuid" url="tree" control-type="selectou" select-type="single"></cloud-tree>
                    </div>
                </div>
            </div>
            <div class="formrow">
                <div class="col-xs-6">
                    <div class="formtitle required">部门名称</div>
                    <div class="formcontent">
                        <input name="OUName" type="text" class="form-control required" placeholder="">
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="formtitle">地址</div>
                    <div class="formcontent">
                        <input name="Address" type="text" class="form-control">
                    </div>
                </div>

            </div>
            <div class="formrow">
                <div class="col-xs-6">
                    <div class="formtitle">邮编</div>
                    <div class="formcontent">
                        <input name="PostalCode" type="text" class="form-control">
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="formtitle">电话</div>
                    <div class="formcontent">
                        <input name="Tel" type="text" class="form-control">
                    </div>
                </div>
            </div>
            <div class="formrow">
                <div class="col-xs-6">
                    <div class="formtitle">传真</div>
                    <div class="formcontent">
                        <input name="Fax" type="text" class="form-control">
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="formtitle">排序</div>
                    <div class="formcontent">
                        <input name="SortNum" type="text" class="form-control" placeholder="" value="0">
                    </div>
                </div>
            </div>
            <div class="formrow" id="tanantrow">
                <div class="col-xs-12">
                    <div class="formtitle required">关联租户</div>
                    <div class="formcontent">
                        <input id="TenantName" name="TenantName" type="text" class="form-control required" placeholder="点击选择" onclick="ContactTenant()">
                    </div>
                </div>
            </div>
            <div class="formrow" style="display:none">
                <input id="TenantID" name="TenantID" type="text" class="form-control" placeholder="" value="0">
            </div>
            <div class="row formbtnop">
                <button class="btn btn-primary cloudbtn" type="button" onclick="Save()">保 存</button>
                <button class="btn cloudbtn" type="button" onclick="Close()">关 闭</button>
            </div>
        </form>
    </div>
    <script>
        var validator = $("#form").validate();
        var ParentOUGuid = GetUrlParam("parentouguid");
        $(function () {
            if (ParentOUGuid != "Top") {
                $("#tanantrow").remove();
                $("#TenantID").remove();
            }
            $("#ParentOUGuid").attr("selectvalue", ParentOUGuid);
            RenderTree();
        })

        function Save() {
            if (validator.form()) {
                var param = $("#form").GetForm();
                param.ParentOUGuid = GetTreeSelectValue("ParentOUGuid")
                CloudPost(param, "opinsert", function (res) {
                    if (res.code == 0) {
                        OpenSuccess("保存成功！", function () {
                            CloseDialog();
                        })
                    } else {
                        OpenFail(res.data)
                    }
                })
            }
        }
        function Close() {
            CloseDialog();
        }
        function ContactTenant() {
            OpenTopDialog("选择租户", "frame/org/tenant/contact", 400, 800, function (ReturnValue) {
                $("#TenantName").val(ReturnValue.TenantName)
                $("#TenantID").val(ReturnValue.TenantID)
            })
        }
    </script>
</body>
</html>
